<template>
  <div class="dashboard-container">

    <div class="filter-container">
      <el-row :gutter="10" style="width:100%">
        <el-col :span="4">
          <el-input
            v-model="listQuery.waybill_no"
            placeholder="运单号"
            class="input-with-select"
            clearable
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="4">
          <el-select
            v-model="listQuery.aid"
            style="width:100%"
            filterable
            placeholder="创建人"
            clearable
            @change="reloadList"
          >

            <el-option
              v-for="(item,index) in adminList"
              :key="index"
              :label="item.username"
              :value="item.id"
            />
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-date-picker
            v-model="listQuery.created"
            clearable
            style="width: 100%;"
            type="datetimerange"
            range-separator="~"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="创建开始日期"
            end-placeholder="结束日期"
            :default-time="['00:00:00', '23:59:59']"
            @change="reloadList"
          />
        </el-col>

        <el-col :span="8">
          <div>
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="reloadList"
            >搜索</el-button>
            <!-- <el-button
              class="filter-item"
              style="margin-left: 10px;"
              icon="el-icon-edit"
              type="primary"
              @click="addNews"
            >
              添加
            </el-button> -->
            <el-button
              class="filter-item"
              icon="el-icon-upload"
              type="primary"
              @click="open()"
            >
              导入
            </el-button>

          </div>

        </el-col>

      </el-row>
    </div>
    <div style="padding:0 20px">

      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        height="calc(100vh - 200px)"
        style="width: 100%;"
        size="mini"
        border
        tooltip-effect="dark"
        :header-cell-style="{ background: '#eaf1fd', color: '#333' }"
      >
        <el-table-column
          label="主运单号"
          width="200px"
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.order.first_waybill_no }}</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="从运单号"
          width="200px"
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.order.second_waybill_no }}</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="拦截原因"
          min-width="300px"
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.reason }}</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="created"
          width="140px"
        />
        <el-table-column
          label="创建人"
          prop="admin.username"
          width="140px"
        />
        <el-table-column
          label="操作"
          align="right"
          width="100"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <!-- <el-button
              size="mini"
              type="primary"
              @click="edit(row)"
            >
              编辑
            </el-button> -->
            <el-button
              type="danger"
              @click="delet(row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
    <!-- <Detial :detial="detial" :status="status" :visible="visible" @update="closeDraw" @reload="reloadList" /> -->

    <Upload :visible="upLoadDraw" @update="closeDraw" @reload="reloadList" />

  </div>
</template>

<script>
import { listStop, delStop } from '@/api/base/intercept'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
// import Detial from './components/templateDetial.vue'
import Upload from './components/Upload'
import { listAdmin } from '@/api/admin/index'

export default {
  name: 'Dashboard',
  components: {
    Pagination,
    Upload
  },
  data() {
    return {
      data_arr: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        waybill_no: '',
        created: '',
        aid: ''
      },
      visible: false,
      status: 1,
      id: '',
      detial: {},
      upLoadDraw: false,
      adminList: []
    }
  },
  computed: {
  },
  created() {
    this.getList()
    this.getAdminList()
  },
  methods: {
    getAdminList() {
      listAdmin({
        status: 1,
        limit: 10000
      }).then(response => {
        this.adminList = response.data.data
      })
    },
    closeDraw() {
      this.visible = false
      this.upLoadDraw = false
    },
    addNews() {
      this.status = 1
      this.visible = true
    },
    edit(row) {
      this.detial = { ...row }
      this.status = 2
      this.visible = true
    },
    delet(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delStop({
          tid: row.tid
        }).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
      }).catch(() => {

      })
    },
    reloadList() {
      this.listQuery.page = 1
      this.visible = false
      this.getList()
    },
    getList() {
      this.listLoading = true
      listStop(this.listQuery).then(response => {
        this.list = response.data.list
        this.total = response.data.count
        this.listLoading = false
      })
    },
    open() {
      this.upLoadDraw = true
    }
  }
}
</script>
<style scoped lang='scss'>
.filter-container{
  padding:20px 20px 10px;
  display: flex;
}

.upload-demo{
  margin: 20px 0 10px;
}
/**
 * `@property` is required for the animation to work.
 * Without it, the angle values won’t interpolate properly.
 *
 */
@property --bg-angle {
  inherits: false;
  initial-value: 0deg;
  syntax: "<angle>";
}

/**
 * To animate the gradient, we set the custom property to 1 full
 * rotation. The animation starts at the default value of `0deg`.
 */
@keyframes spin {
  to {
    --bg-angle: 360deg;
  }
}

article {
  /* add the animation, but pause it by default */
  animation: spin 2.5s infinite linear paused;

  /**
   * Using `background-origin` we can create a “border” using two gradients. And to
   * make the gradients better-looking, we use OKLCH.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/background-origin
   * @see https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl
   */
  background:
    /* Background colors don’t work with `background-origin`, so use a gradient. */
    linear-gradient(
        to bottom,
        oklch(0.1 0.2 240 / 0.95),
        oklch(0.1 0.2 240 / 0.95)
      )
      padding-box, /* ends at inner border edges */
    conic-gradient(
        from var(--bg-angle) in oklch longer hue,
        oklch(1 0.37 0) 0 0
      )
      border-box; /* extends to outer border edges */

  /* a clear border lets the background gradient shine through */
  border: 6px solid transparent;

  /* unpause the animation on hover */
  &:hover {
    animation-play-state: running;
  }
}
article {
  border-radius: 1rem;
  // box-shadow: 0.125rem 0.25rem 0.25rem 0.5rem oklch(0.1 0.37 315 / 0.25);
  color: white;
  padding: 1rem;
  width: min(400px, 90vw);
}
</style>
